﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

using Styx;
using Styx.Helpers;
using Styx.Loaders;
using Styx.Patchables;
using Styx.Plugins;
using Styx.Common;
using Styx.CommonBot;
using Styx.Pathing;
using Styx.CommonBot.Profiles;
using Styx.WoWInternals;
using Styx.WoWInternals.Misc;
using Styx.WoWInternals.World;
using Styx.WoWInternals.WoWCache;
using Styx.WoWInternals.WoWObjects;

using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Media;

using BrodieHPlugin;
using BrodieHProfile;
using BrodieHQB;
using BarryDurex;
using KatzerleAvoid;

using ObjectManager = Styx.WoWInternals.ObjectManager;

namespace BrodiesPlugin
{
    public class BrodiesPlugin : HBPlugin
    {
        public bool hasBeenInitialized = false;
        public bool hasBeenInitialized2 = false;
        public bool hasBeenInitialized3 = false;
        public static bool hasBeenInitialized4 = false;
		public bool hasBeenInitialized5 = false;
        public bool brodieupdated = false;
        
        #region Overrides except pulse
        public override string Author { get { return "TheBrodieMan"; } }
        public override Version Version { get { return new Version(1, 4, 5); } }
        public override string Name { get { return "TheBrodieMan's Compendium"; } }
        public override bool WantButton { get { return true; } }
        public override string ButtonText { get { return "Settings"; } }
        public override void OnButtonPress()
        {
            bool isRunningantes = TreeRoot.IsRunning;
            if (isRunningantes)
            {
                MessageBox.Show("Bot is running, stop bot before initiate Brodies Plugin", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                abreJanela();
            }
        }
        private Brodie_Plugin_Updater UpdaterPlugin;
        private Brodie_QB_Updater UpdaterQB;
        private Brodie_Profile_Updater UpdaterProfile;
		//public static ProfileSwapperSettings Settings = new ProfileSwapperSettings();

        public override void Initialize()
        {
            if (!hasBeenInitialized)
            {
                Logging.Write(Colors.Teal, "Loaded TheBrodieMan's Compendium Plugin v" + Version.ToString());
                Logging.Write(Colors.Teal, "Please Wait While [Brodies Plugin] Checks For Updates, This MAY Take Several Minutes");
                hasBeenInitialized = true;
                try
                {
                    UpdaterPlugin = new Brodie_Plugin_Updater("https://tbmpplugin.googlecode.com/svn/trunk/", "BrodiesPlugin");
                    if (UpdaterPlugin.UpdateAvailable())
                    {
                        Logging.Write("[Brodies Plugin] Update to $" + UpdaterPlugin.GetNewestRev().ToString() + " is available! You are on $" + UpdaterPlugin.CurrentRev.ToString());
                        Logging.Write("[Brodies Plugin] Starting update process...");
                        if (UpdaterPlugin.Update())
                        {
                            Logging.Write("[Brodies Plugin] Plugin is now up to date! HB Reload REQUIRED");
                            brodieupdated = true;
                        }
                        else
                        {
                            Logging.Write("[Brodies Plugin] Error trying to auto-update. Please update manually!");
                        }
                    }
                    else
                    {
                        Logging.Write("[Brodies Plugin] is at Rev $" + UpdaterPlugin.CurrentRev.ToString() + " and is up to date!");
                    }
                }
                catch (Exception ex)
                {
                    Logging.Write(Colors.Teal, "Unable to run [Brodies Plugin] update process");
                    Logging.Write(LogLevel.Diagnostic, "[Brodies Plugin]: Exception " + ex.Message);
                }
                try
                {
                    UpdaterQB = new Brodie_QB_Updater("https://tbmpqb.googlecode.com/svn/trunk/", "");
                    if (UpdaterQB.UpdateAvailable())
                    {
                        Logging.Write("[Brodies QB Updater] Update to $" + UpdaterQB.GetNewestRev().ToString() + " is available! You are on $" + UpdaterQB.CurrentRev.ToString());
                        Logging.Write("[Brodies QB Updater] Starting update process...");
                        if (UpdaterQB.Update())
                        {
                            Logging.Write("[Brodies QB Updater] QBs are now up to date! HB Reload REQUIRED");
                            brodieupdated = true;
                        }
                        else
                        {
                            Logging.Write("[Brodies QB Updater] Error trying to auto-update. Please update manually!");
                        }
                    }
                    else
                    {
                        Logging.Write("[Brodies QB Updater] is at Rev $" + UpdaterQB.CurrentRev.ToString() + " and is up to date!");
                    }
                }
                catch (Exception ex)
                {
                    Logging.Write(Colors.Teal, "Unable to run [Brodies QB Updater] update process");
                    Logging.Write(LogLevel.Diagnostic, "[Brodies QB Updater]: Exception " + ex.Message);
                }
                try
                {
                    UpdaterProfile = new Brodie_Profile_Updater("https://tbmpprofiles.googlecode.com/svn/trunk/", "");
                    if (UpdaterProfile.UpdateAvailable())
                    {
                        Logging.Write("[Brodies Profile Updater] Update to $" + UpdaterProfile.GetNewestRev().ToString() + " is available! You are on $" + UpdaterProfile.CurrentRev.ToString());
                        Logging.Write("[Brodies Profile Updater] Starting update process...");
                        if (UpdaterProfile.Update())
                        {
                            Logging.Write("[Brodies Profile Updater] Profiles are now up to date!");
                        }
                        else
                        {
                            Logging.Write("[Brodies Profile Updater] Error trying to auto-update. Please update manually!");
                        }
                    }
                    else
                    {
                        Logging.Write("[Brodies Profile Updater] is at Rev $" + UpdaterProfile.CurrentRev.ToString() + " and is up to date!");
                    }
                }
                catch (Exception ex)
                {
                    Logging.Write(Colors.Teal,"Unable to run [Brodies Profile Updater] update process");
                    Logging.Write(LogLevel.Diagnostic, "[Brodies Profile Updater]: Exception " + ex.Message);
                }
                BrodiesPluginUI.BPGlobalSettings.Instance.Load();
				BrodiesPluginUI.BPSettings.Instance.Load();
              }
			  
            if (!hasBeenInitialized2)
            {
                hasBeenInitialized2 = true;
                return;
            }
			
            if (!hasBeenInitialized3)
            {
                hasBeenInitialized3 = true;
                return;
            }
			
            abreJanela();
        }

        public override void Dispose()
        {
            Logging.Write(Colors.Teal, "[Brodies Plugin] Deactivation Complete");
        }
		#region Some Quest Helper Functions

		public bool IsOnQuest(uint questId)
		{
			return Me.QuestLog.GetQuestById(questId) != null && !Me.QuestLog.GetQuestById(questId).IsCompleted;
		}

		public bool QuestComplete(uint questId)
		{
			return Me.QuestLog.GetQuestById(questId).IsCompleted;
		}

		public bool QuestFailed(uint questId)
		{
			return Me.QuestLog.GetQuestById(questId).IsFailed;
		}

		public bool ItemOnCooldown(uint ItemId)
		{
			return Lua.GetReturnVal<bool>("GetItemCooldown(" + ItemId + ")", 0);
		}

		public void UseQuestItem(uint ItemId)
		{
			Lua.DoString("UseItemByName(" + ItemId + ")");
		}

		public void UseIfNotOnCooldown(uint ItemId)
		{
			if (!ItemOnCooldown(ItemId))
			{
				UseQuestItem(ItemId);
			}
		}

		public bool QuestObjectiveComplete(uint questId, int objectiveNum)
		{
			return (Lua.GetReturnVal<int>("a,b,c=GetQuestLogLeaderBoard(" + objectiveNum + ",GetQuestLogIndexByID(" + questId + "));if c==1 then return 1 else return 0 end", 0) == 1);
		}

        private bool IsObjectiveComplete(int objectiveId, uint questId)
        {
            if (Me.QuestLog.GetQuestById(questId) == null)
            {
                return false;
            }
            int returnVal = Lua.GetReturnVal<int>("return GetQuestLogIndexByID(" + questId + ")", 0);
            return
                Lua.GetReturnVal<bool>(
                    string.Concat(new object[] { "return GetQuestLogLeaderBoard(", objectiveId, ",", returnVal, ")" }), 2);
        }

		public bool TargetingNpc(uint npcId)
		{
			return Me.CurrentTarget.Entry == npcId;
		}

		public bool HasQuest(uint questId)
		{
			return Me.QuestLog.GetQuestById(questId) != null;
		}
		
		#endregion

        #endregion

        #region Privates/Publics
        private void abreJanela()
        {
            if (brodieupdated)
            {
                MessageBox.Show("Brodies Plugin/Quest Behaviors has been updated a restart is required.", "RESTART REQUIRED", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            var mainBrodiePluginUI = new BrodiesPluginUI();
            mainBrodiePluginUI.ShowDialog();
        }

        private static LocalPlayer Me { get { return StyxWoW.Me; } }
        #endregion
		
		#region Mobs for Spell Avoidance (And Dailies)

		public WoWUnit JungleShredder { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 67285 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit MasterCaller { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 69286 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit MechaPounder { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 67967 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit ShredmasterP { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 67371 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit DreadKunchong { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 64717 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit Amberhusk { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 64982 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit AScorpion { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 63728 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit ShaoTienSorcerer { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 65133 && u.Distance < 5 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit Tormentor { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 59238 && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit Krichon { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 63978 && u.Distance < 30).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit Cracklefang { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && u.Entry == 58768 && u.IsAlive).FirstOrDefault();}}
		public WoWUnit Sydow { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 63240 && u.IsAlive && u.Distance < 30).FirstOrDefault();}}
		public WoWUnit PrimalDirehorn { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => (u.Entry == 70016 || u.Entry == 69983 || u.Entry == 69142 || u.Entry == 70017 || u.Entry == 70018 || u.Entry == 70019 || u.Entry == 69983 ) && u.IsAlive && u.Distance < 30).FirstOrDefault();}}
		public WoWUnit ZColossus { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 69405 && u.IsAlive && u.Distance < 30).FirstOrDefault();}}
		public WoWUnit MDevilsaur { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 69406 && u.IsAlive && u.Distance < 30).FirstOrDefault();}}
		public List<WoWUnit> VileSpit { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 70571 && u.Distance < 100).ToList();}}
		public List<WoWUnit> MantidNiuzao { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.Entry == 61502 || u.Entry == 61508 || u.Entry == 61509 && u.Distance < 50 && u.IsAlive).OrderBy(u => u.Distance).ToList();}}
		public WoWUnit TimelessBirds { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && (u.Entry == 72762 || u.Entry == 73158) && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit TimelessTurtle { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && (u.Entry == 72765 || u.Entry == 72764 || u.Entry == 72045 || u.Entry == 73161) && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit TimelessOxen { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && (u.Entry == 72843 || u.Entry == 73160 || u.Entry == 72844) && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit TimelessTiger { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && (u.Entry == 72807 || u.Entry == 72805) && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit TimelessRock { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && (u.Entry == 72809) && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit Ordon { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && (u.Entry == 72875 || u.Entry == 72892 || u.Entry == 72895 || u.Entry == 72894) && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit Spineclaw { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && (u.Entry == 72766) && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}
		public WoWUnit SpectralPanda { get { return ObjectManager.GetObjectsOfType<WoWUnit>().Where(u => u.IsValid && (u.Entry == 73018 || u.Entry == 73025 || u.Entry == 73021) && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();}}

		public WoWItem SingingCrystal { get { return Me.BagItems.FirstOrDefault(r => r.Entry == 103641); }}
		public WoWItem BookOfTheAges { get { return Me.BagItems.FirstOrDefault(r => r.Entry == 103642); }}
		public WoWItem DewOfEternalMorning { get { return Me.BagItems.FirstOrDefault(r => r.Entry == 103643); }}
		public WoWItem CrystalOfInsanity { get { return Me.BagItems.FirstOrDefault(r => r.Entry == 86569); }}
		#endregion

        #region Override Pulse
        public override void Pulse()
        {
			if (Me == null || !StyxWoW.IsInGame)
				return;
            if (Me.IsDead || Me.IsGhost)
				return;
			if (Battlegrounds.IsInsideBattleground || Me.IsInInstance || Me.IsOnTransport)
				return;
			ObjectManager.Update();
			
			#region PROFILE SWAPPER CODE
			if (BrodiesPluginUI.BPSettings.Instance.Active13)
			{
				if (!hasBeenInitialized5)
				{
					if (BrodiesPluginUI.BPSettings.Instance.Active1)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile1);
						hasBeenInitialized5 = true;
					}
					else if (BrodiesPluginUI.BPSettings.Instance.Active2)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile2);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active3)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile3);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active4)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile4);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active5)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile5);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active6)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile6);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active7)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile7);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active8)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile8);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active9)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active10)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active11)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						hasBeenInitialized5 = true;
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active12)
					{
						ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						hasBeenInitialized5 = true;
					}
					else
					{
						Logging.Write(Colors.Red, "[Brodies Plugin] Profile Swapper: Init failed - No profiles selected");
					}
					Logging.Write(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper: Init Done");
				}
				
				if (StyxWoW.Me.IsCasting && (StyxWoW.Me.CastingSpellId == 556 || StyxWoW.Me.CastingSpellId == 8690 || StyxWoW.Me.CastingSpellId == 94719 || StyxWoW.Me.CastingSpellId == 136508 || StyxWoW.Me.CastingSpellId == 75136 || StyxWoW.Me.CastingSpellId == 82674))
				{
					Logging.Write(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper: Checking to see if we should change profiles");
					if (BrodiesPluginUI.BPSettings.Instance.Active1)
					{
						BrodiesPluginUI.BPSettings.Instance.Active1 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active2)
						{					
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile2);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active3)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile3);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active4)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile4);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active5)
						{
							SpellManager.StopCasting();		
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile5);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active6)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile6);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active7)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile7);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active8)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile8);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active9)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
						
					else if (BrodiesPluginUI.BPSettings.Instance.Active2)
					{
						BrodiesPluginUI.BPSettings.Instance.Active2 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active3)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile3);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active4)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile4);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active5)
						{
							SpellManager.StopCasting();		
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile5);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active6)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile6);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active7)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile7);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active8)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile8);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active9)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
						
					else if (BrodiesPluginUI.BPSettings.Instance.Active3)
					{
						BrodiesPluginUI.BPSettings.Instance.Active3 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active4)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile4);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active5)
						{
							SpellManager.StopCasting();		
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile5);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active6)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile6);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active7)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile7);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active8)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile8);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active9)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
						
					else if (BrodiesPluginUI.BPSettings.Instance.Active4)
					{
						BrodiesPluginUI.BPSettings.Instance.Active4 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active5)
						{
							SpellManager.StopCasting();		
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile5);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active6)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile6);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active7)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile7);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active8)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile8);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active9)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
									
					else if (BrodiesPluginUI.BPSettings.Instance.Active5)
					{
						BrodiesPluginUI.BPSettings.Instance.Active5 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active6)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile6);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active7)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile7);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active8)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile8);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active9)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active6)
					{
						BrodiesPluginUI.BPSettings.Instance.Active6 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active7)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile7);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active8)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile8);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active9)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
						
					else if (BrodiesPluginUI.BPSettings.Instance.Active7)
					{
						BrodiesPluginUI.BPSettings.Instance.Active7 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active8)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile8);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active9)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
						
					else if (BrodiesPluginUI.BPSettings.Instance.Active8)
					{
						BrodiesPluginUI.BPSettings.Instance.Active8 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active9)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile9);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
						
					else if (BrodiesPluginUI.BPSettings.Instance.Active9)
					{
						BrodiesPluginUI.BPSettings.Instance.Active9 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active10)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile10);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
						
					else if (BrodiesPluginUI.BPSettings.Instance.Active10)
					{
						BrodiesPluginUI.BPSettings.Instance.Active10 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active11)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile11);
						}
						else if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}
						
					else if (BrodiesPluginUI.BPSettings.Instance.Active11)
					{
						BrodiesPluginUI.BPSettings.Instance.Active11 = false;

						if (BrodiesPluginUI.BPSettings.Instance.Active12)
						{
							SpellManager.StopCasting();	
							ChangeProfile(BrodiesPluginUI.BPSettings.Instance.Profile12);
						}
						else
						{
						// Stop Bot
						}
					}

					else if (BrodiesPluginUI.BPSettings.Instance.Active12)
					{
						Logging.WriteDiagnostic(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper has run out of profiles to use. Thank you come again!");
					}
				}
			}
			#endregion

			#region [Operation Shieldwall/Dominance Offensive]

			#region Jungle Shredder
			//http://www.wowhead.com/quest=32446
			if (IsOnQuest(32446) && !JungleShredder.HasAura(135422))
			{
				if (Me.Combat && JungleShredder != null && JungleShredder.Distance2D <= 10)
					UseIfNotOnCooldown(93180); //Re-Configured Remote
			}
			#endregion
			
			#region Mecha-Pounder
			//http://www.wowhead.com/quest=32238
			if (IsOnQuest(32238) && !MechaPounder.HasAura(133955))
			{
				if (Me.Combat && MechaPounder != null && MechaPounder.Distance2D <= 10)
					UseIfNotOnCooldown(91902); //Universal remote
			}
			#endregion

			#region Shredmaster Packle
			//http://www.wowhead.com/quest=32158
			if (ShredmasterP != null)
			{
				if (Me.Combat && ShredmasterP.Distance2D <= 10 && ShredmasterP.IsCasting && ShredmasterP.CastingSpellId == 135865)
					BarryDurex.QuestHelper.AvoidEnemyCast(ShredmasterP, 80, 10);
			}
			#endregion
			#endregion
			
			#region [Cloud Serpent]
			
			#region http://www.wowhead.com/quest=31717
			if (Me.HasAura("Hot Foot!"))
				BarryDurex.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurex.QuestHelper.getHotFootList, "Hot Foot!", 15);
			#endregion
			
			#region http://www.wowhead.com/quest=32158
			if (Me.HasAura("Ignite Fuel"))
				BarryDurex.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurex.QuestHelper.getIgniteFuelList, "Ignite Fuel", 15);			
			#endregion
			
			#region http://www.wowhead.com/quest=31717
			if (Me.HasAura("Solar Beam"))
				BarryDurex.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurex.QuestHelper.getSolarBeamList, "Solar Beam", 15);
			#endregion
			#endregion

			#region [Golden Lotus]

			#region Lightning Pool
			if (Me.HasAura("Lightning Pool"))
				BarryDurex.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurex.QuestHelper.getLightningPoolList, "Lightning Pool", 15);
			#endregion
			
			#region http://www.wowhead.com/quest=30251
			if (Me.HasAura("Caustic Pitch"))
				BarryDurex.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurex.QuestHelper.getCausticPitchList, "Caustic Pitch", 15);
			#endregion

			if (Me.HasAura("Venom Splash") && BarryDurex.QuestHelper.getVenomSplashList != null && BarryDurex.QuestHelper.getVenomSplashList[0].Distance < (BarryDurex.QuestHelper.getVenomSplashList[0].Radius * 1.6f))
				BarryDurex.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurex.QuestHelper.getVenomSplashList, "Venom Splash", 15);

			#region http://www.wowhead.com/quest=30320
			if (Me.HasAura("Spirit Void"))
			{
				if (!IsOnQuest(30320))
				{
					Me.Auras["Spirit Void"].TryCancelAura();
					Thread.Sleep(200);
				}
				else
				{
					if (!Me.Combat && !Me.Mounted)
						Flightor.MountHelper.MountUp();

					if (Me.Mounted && (Me.Combat || (Tormentor != null && Tormentor.Location.Distance(Me.Location) < 10)))
					{ WoWMovement.Move(WoWMovement.MovementDirection.JumpAscend); Thread.Sleep(836); WoWMovement.MoveStop(); }
				}
			}
			#endregion

			#region http://www.wowhead.com/quest=30482
			if (IsOnQuest(30482) && !QuestComplete(30482))
			{
				if (Sydow != null && Sydow.CastingSpellId == 126347)
					BarryDurex.QuestHelper.AvoidEnemyCast(Sydow, 80, 15);
			}
			#endregion

			#region http://www.wowhead.com/quest=30233
			if (Cracklefang != null && Cracklefang.Distance2D <= 20 && Cracklefang.IsCasting)
				BarryDurex.QuestHelper.AvoidEnemyCast(Cracklefang, 90, 20);
			#endregion

			#region http://www.wowhead.com/quest=30249
			if (IsOnQuest(30249))
			{
				if (Krichon != null && Krichon.IsCasting && !Me.IsBehind(Krichon))
					BarryDurex.QuestHelper.AvoidEnemyCast(Krichon, 80, 15);
			}
			#endregion
			
			if (ShaoTienSorcerer != null)
			{
				if (Me.Combat && ShaoTienSorcerer.Distance2D <= 10 && ShaoTienSorcerer.IsCasting && ShaoTienSorcerer.CastingSpellId == 127552)
					BarryDurex.QuestHelper.AvoidEnemyCast(ShaoTienSorcerer, 80, 15);
			}
			
			#endregion

			#region [The August Celestials]
			// http://www.wowhead.com/quest=30952 http://www.wowhead.com/quest=30953 http://www.wowhead.com/quest=30954 http://www.wowhead.com/quest=30955
			// http://www.wowhead.com/quest=30956 http://www.wowhead.com/quest=30957 http://www.wowhead.com/quest=30958 http://www.wowhead.com/quest=30959
			if (IsOnQuest(30952) || IsOnQuest(30953) || IsOnQuest(30954) || IsOnQuest(30955) || IsOnQuest(30956) || IsOnQuest(30957) || IsOnQuest(30958) || IsOnQuest(30959))
			{
				if (Me.Combat && Me.IsMoving)
				{
					ObjectManager.Update();
					Thread.Sleep(200);
					if (MantidNiuzao != null)
					{
						MantidNiuzao[0].Face();
						MantidNiuzao[0].Target();
						WoWMovement.MoveStop();
						Thread.Sleep(1000);
					}
				}
			}
			#endregion

			#region [Klaxxi]
			// http://www.wowhead.com/quest=31487
			if (IsOnQuest(31487))
			{
				if (Me.Combat && DreadKunchong != null && DreadKunchong.Distance2D <= 10)
					UseIfNotOnCooldown(87394); //Sonic Disruption Fork
			}
			if (DreadKunchong != null)
			{
				if (Me.Combat && DreadKunchong.Distance2D <= 15 && DreadKunchong.IsCasting && DreadKunchong.CastingSpellId == 128022)
					BarryDurex.QuestHelper.AvoidEnemyCast(DreadKunchong, 80, 15);
			}
			
			// http://www.wowhead.com/quest=31268
			if (IsOnQuest(31268))
			{
				if (Me.Combat && AScorpion != null && AScorpion.Distance2D <= 10)
					UseIfNotOnCooldown(85884); //Sonic Emitter
			}
			
			// http://www.wowhead.com/quest=31507
			if (IsOnQuest(31507))
			{
				if (Me.Combat && Amberhusk != null && Amberhusk.Distance2D <= 15)
				{
					UseIfNotOnCooldown(87841);
					SpellManager.ClickRemoteLocation(Amberhusk.Location);
				}
			}
			#endregion

			#region Isle of Thunder
			
			if (Me.Combat && ZColossus != null)
			{
				if (ZColossus.Distance2D <= 15 && ZColossus.IsCasting && ZColossus.CastingSpellId == 140239)
					BarryDurex.QuestHelper.AvoidEnemyCast(ZColossus, 80, 15);
				if (ZColossus.Distance2D <= 15 && ZColossus.IsCasting && ZColossus.CastingSpellId == 140254)
					BarryDurex.QuestHelper.AvoidEnemyCast(ZColossus, 80, 15);
			}
			
			if (MDevilsaur != null && Me.Combat)
			{
				while (VileSpit[0].Location.Distance(Me.Location) <= 15)
				{
					WoWMovement.Move(WoWMovement.MovementDirection.StrafeRight, TimeSpan.FromSeconds(1));
					Thread.Sleep(100);
				}
				if (MDevilsaur.Distance2D <= 50 && MDevilsaur.IsCasting && MDevilsaur.CastingSpellId == 140424)
					BarryDurex.QuestHelper.AvoidEnemyCast(MDevilsaur, 150, 50);
				if (MDevilsaur.Distance2D <= 50 && MDevilsaur.IsCasting && MDevilsaur.CastingSpellId == 140427)
					BarryDurex.QuestHelper.AvoidEnemyCast(MDevilsaur, 150, 50);
				if (MDevilsaur.Distance2D <= 100 && MDevilsaur.IsCasting && (MDevilsaur.CastingSpellId == 140397 || MDevilsaur.CastingSpellId == 140407 || MDevilsaur.CastingSpellId == 140406 || MDevilsaur.CastingSpellId == 140405))
					BarryDurex.QuestHelper.AvoidEnemyCast(MDevilsaur, 120, 100);
			}
			
			#endregion
			
			#region Isle of Giants
			if (PrimalDirehorn != null)
			{
				if (Me.Combat && PrimalDirehorn.Distance2D <= 15 && PrimalDirehorn.IsCasting && PrimalDirehorn.CastingSpellId == 138772)
					BarryDurex.QuestHelper.AvoidEnemyCast(PrimalDirehorn, 90, 15);
			}			
			#endregion
			
			#region Timeless Isle
			
			if (CrystalOfInsanity != null && !Me.HasAura(127230))
				UseIfNotOnCooldown(86569);
			
			if (Me.ZoneId == 6757)
			{
				if (SingingCrystal != null && !Me.HasAura(147055))
					UseIfNotOnCooldown(103641);
				
				if (BookOfTheAges != null && !Me.HasAura(147226))
					UseIfNotOnCooldown(103642);
				
				if (DewOfEternalMorning != null && !Me.HasAura(147476))
					UseIfNotOnCooldown(103643);
			}
			
			if (Me.Combat && TimelessBirds != null)
			{
				// Gust of Wind
				if (TimelessBirds.Distance2D <= 15 && TimelessBirds.IsCasting && TimelessBirds.CastingSpellId == 147310)
					BarryDurex.QuestHelper.AvoidEnemyCast(TimelessBirds, 90, 15);
			}
			
			if (Me.Combat && TimelessTurtle != null)
			{
				// Geyser (Elder Great Turtle only)
				if (TimelessTurtle.Distance2D <= 15 && TimelessTurtle.IsCasting && TimelessTurtle.CastingSpellId == 147573)
					BarryDurex.QuestHelper.AvoidEnemyCast(TimelessTurtle, 90, 15);
					
				// Shell Spin (version 1)
				if (TimelessTurtle.Location.Distance(Me.Location) <= 15 && (TimelessTurtle.CastingSpellId == 147590 || TimelessTurtle.HasAura(147590)))
					KatzerleAvoid.RunAwayCode.FleeingFromEnemy(TimelessTurtle, 147590, 20, 10, 5);
				
				// Shell Spin (version 2)
				if (TimelessTurtle.Location.Distance(Me.Location) <= 15 && (TimelessTurtle.CastingSpellId == 147571 || TimelessTurtle.HasAura(147571)))
					KatzerleAvoid.RunAwayCode.FleeingFromEnemy(TimelessTurtle, 147571, 20, 10, 5);
			}
			
			if (Me.Combat && TimelessOxen != null)
			{
				// Headbutt (Version 1)
				if (TimelessOxen.Distance2D <= 20 && TimelessOxen.IsCasting && TimelessOxen.CastingSpellId == 147382)
					BarryDurex.QuestHelper.AvoidEnemyCast(TimelessOxen, 120, 20);

				// Headbutt (Version 2)
				if (TimelessOxen.Distance2D <= 20 && TimelessOxen.IsCasting && TimelessOxen.CastingSpellId == 147384)
					BarryDurex.QuestHelper.AvoidEnemyCast(TimelessOxen, 120, 20);
					
				// Ox Charge
				if (TimelessOxen.Distance2D <= 30 && TimelessOxen.IsCasting && (TimelessOxen.CastingSpellId == 147386 || TimelessOxen.CastingSpellId == 147385))
					BarryDurex.QuestHelper.AvoidEnemyCast(TimelessOxen, 120, 30);
			}
			
			if (Me.Combat && TimelessTiger != null)
			{
				// Rending Swipe
				if (TimelessTiger.Distance2D <= 15 && TimelessTiger.IsCasting && TimelessTiger.CastingSpellId == 147646)
					BarryDurex.QuestHelper.AvoidEnemyCast(TimelessTiger, 120, 15);
					
				// Greater Swipe
				if (TimelessTiger.Distance2D <= 15 && TimelessTiger.IsCasting && TimelessTiger.CastingSpellId == 147652)
					BarryDurex.QuestHelper.AvoidEnemyCast(TimelessTiger, 150, 15);
			}
			
			if (Me.Combat && TimelessRock != null)
			{
				// Stomp (Version 1)
				if (TimelessRock.Location.Distance(Me.Location) <= 15 && (TimelessRock.CastingSpellId == 147500 || TimelessRock.HasAura(147500)))
					KatzerleAvoid.RunAwayCode.FleeingFromEnemy(TimelessRock, 147500, 40, 10, 5);
				
				// Stomp (Version 2)
				if (TimelessRock.Location.Distance(Me.Location) <= 15 && (TimelessRock.CastingSpellId == 147512 || TimelessRock.HasAura(147512)))
					KatzerleAvoid.RunAwayCode.FleeingFromEnemy(TimelessRock, 147512, 40, 10, 5);
			}
			
			if (Me.Combat && SpectralPanda != null)
			{
				// Spinning Crane Kick
				if (SpectralPanda.Location.Distance(Me.Location) <= 15 && (SpectralPanda.CastingSpellId == 148730 || SpectralPanda.HasAura(148730)))
					KatzerleAvoid.RunAwayCode.FleeingFromEnemy(SpectralPanda, 148730, 30, 10, 5);
			}
			
			if (Me.Combat && Spineclaw != null)
			{
				// Claw Flurry
				if (Spineclaw.Distance2D <= 15 && Spineclaw.IsCasting && Spineclaw.CastingSpellId == 147557)
					BarryDurex.QuestHelper.AvoidEnemyCast(Spineclaw, 120, 15);
			}
			
			if (Me.Combat && Ordon != null)
			{
				// Breath of Fire
				if (Ordon.Distance2D <= 15 && Ordon.IsCasting && Ordon.CastingSpellId == 147416)
					BarryDurex.QuestHelper.AvoidEnemyCast(Ordon, 120, 15);

				// Crackling Blow
				if (Ordon.Distance2D <= 15 && Ordon.IsCasting && Ordon.CastingSpellId == 147674)
					BarryDurex.QuestHelper.AvoidEnemyCast(Ordon, 120, 15);

				// Burning Sacrifice
				if (Ordon.Distance2D <= 15 && Ordon.IsCasting && Ordon.CastingSpellId == 147422)
					KatzerleAvoid.RunAwayCode.FleeingFromEnemy(Ordon, 147422, 30, 10, 5);
				
				// Blazing Cleave
				if (Ordon.Distance2D <= 15 && Ordon.IsCasting && Ordon.CastingSpellId == 147702)
					KatzerleAvoid.RunAwayCode.FleeingFromEnemy(Ordon, 147702, 30, 10, 5);
					
				// Defensive Shield
				if (Me.CurrentTarget != null && Me.CurrentTarget.HasAura(147689))
					BarryDurex.QuestHelper.AvoidEnemyCast(Ordon, 120, 40);
			}
			
			#endregion
        }
        #endregion
		
		static public void ChangeProfile(string Profile)
		{
			Logging.Write(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper: Load Profile: {0}", Profile);
			WoWMovement.MoveStop();
			Thread.Sleep(1000);
			ProfileManager.LoadNew(Profile);
			Thread.Sleep(1000);
			Logging.Write(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper: Load Profile: {0} done", Profile);
		}
		
		static public string FolderPath
        {
            get
            {
                string sPath = Process.GetCurrentProcess().MainModule.FileName;
                sPath = Path.GetDirectoryName(sPath);
                sPath = Path.Combine(sPath, "Plugins\\BrodiesPlugin\\");
                return sPath;
            }
        }
		
		static public bool inCombat
		{
			get
			{
				if (Me == null || !StyxWoW.IsInGame || Me.Combat || Me.IsDead || Me.IsGhost || InPetCombat()) return true;
				return false;
			}
		}
		
		static public bool InPetCombat()
        {
            List<string> cnt = Lua.GetReturnValues("dummy,reason=C_PetBattles.IsTrapAvailable() return dummy,reason");

            if (cnt != null) { if (cnt[1] != "0") return true; }
            return false;
        }
    }
}
